package com.lingtu.shopwxserver.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * @ClassName TestController
 * @Description 测试controller
 * @Author MaShuai
 * @Date 2018/11/22 16:23
 * @Version 1.0
 **/
@Controller
public class TestController {

    @Value("${web.upload-path}")
    private String path;

    @RequestMapping(value = "/index")
    public String to(Model model){
        File file;

        {
            try {

                ClassPathResource resource = new ClassPathResource("application.yml");
                InputStream inputStream = resource.getInputStream();
                System.out.println(inputStream.toString());
                file = ResourceUtils.getFile("classpath:static/image/shop.png");
                System.out.println("path:"+file.getAbsolutePath());
                model.addAttribute("file",file.getAbsolutePath());
                model.addAttribute("name",file.getName());
                model.addAttribute("path",path);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return "index";
    }
}
